
Yacon.widget.FrameMenu = function(conText)
{
	this.appFrame   = 0;	
	Yacon.apply(this,conText);
	this.create();
}

Yacon.widget.FrameMenu.Extend(Object,{	
	
	create:function()
	{
	
	}
})

Yacon.widget.LeftMenu = function(conText)
{
	this.childCount  = 0;
	this.childs      = new Array();
	this.hideType    = Yacon.widget.HIDE_TYPE_WORK;
	Yacon.apply(this,conText);
	this.create();
}

Yacon.widget.LeftMenu.Extend(Yacon.widget.WinControl,{	
	
	create:function()
	{
		if (!this.element)
			this.element  = document.getElementById(this.elementID);	
		
		if (!this.element ||!this.element.rows)
			return;	
		
		this.element.Control   = this;		
		this.hideType = this.element.getAttribute("hideType");
	   
		for(var i=0; i<this.element.rows.length; i++)
		{
			this.childs[this.childCount] = document.all(this.elementID+"_level"+i);			
			this.childs[this.childCount].Control = this;
			if (this.childs[this.childCount].rows[0].getAttribute("isExpand").isEqual("true"))
			{
				this.setActiveMenu(this.childs[this.childCount]);
			}
			this.childCount ++;
		}	
	},
	setExpanded:function(expMenu)
	{
		
		if (expMenu.className.isEqual("menulevel"))
		{
		
			if (Yacon.isObject(expMenu.rows[0]))
			{
				
				expMenu.rows[0].className = "aleveltitle";
				expMenu.rows[0].setAttribute("isExpand","true");
				
				if (expMenu.rows.length==2)
					expMenu.rows[1].style.display= "";
			}	
		}		
	},
	setHidden:function(hiddenMenu)
	{
		if (hiddenMenu.className.isEqual("menulevel"))
		{
			if (Yacon.isObject(hiddenMenu.rows[0]))
			{
				hiddenMenu.rows[0].className = "leveltitle";
				hiddenMenu.rows[0].setAttribute("isExpand","false");
				if (hiddenMenu.rows.length==2)
					hiddenMenu.rows[1].style.display= "none";	
				
			}	
		}		
	},
	setActiveMenu:function(activeMenu)
	{
		
		if (this.hideType.isEqual(Yacon.widget.HIDE_TYPE_CHECK))
		{
			if (Yacon.isObject(this.activeMenuItem))
			{
				this.setHidden(this.activeMenuItem);
				this.activeMenuItem = null;				
			}
		
			if (this.activeMenuItem != activeMenu)
			{
				this.setExpanded(activeMenu);
				this.activeMenuItem = activeMenu;
			}
		}else
		{
			if (activeMenu.rows[0]&& activeMenu.rows[0].getAttribute("isExpand").isEqual("false"))
				this.setExpanded(activeMenu);
			else
				this.setHidden(activeMenu);
		}
	},
	setMenuPage:function(menuItem)
	{
		if (!Yacon.isEmpty(menuItem.getAttribute("url")))
		{
			var url = menuItem.getAttribute("url");
			if (url.contains("?"))
				url = url+"&sessionID="+window.sessionID;
			else
				url = url+"?sessionID="+window.sessionID;
			
			parent.window.workFrame.location.replace(contextPath + url);
		}
	}

})

Yacon.widget.LeftMenu.events = {
	onTitleClick:function()
	{
		var element   = Yacon.getTR(event.srcElement);
		var clickName = element.getAttribute("menuclick");
		
		if (Yacon.isEmpty(clickName))
		{
			var chTable = Yacon.getTable(element);
			if (Yacon.isObject(chTable.Control))
			{
				chTable.Control.setActiveMenu(chTable);
				chTable.Control.setMenuPage(element);
			}
		}else if (Yacon.getInt(clickName)<0)
		{
			Yacon.fireUserEvent(clickName+"_onclick");
		}		
		//ÏÂÃæµÄ¹¦ÄÜÊÇ²»ÊÇ¿´×Å¶àÓà°¡
		this.clearActState() ;
		element.className = "aleveltitle";
		element.acton="true" ;
	},
	onTitleMouseover:function()
	{
		var element   = Yacon.getTR(event.srcElement);	
		element.className = "aleveltitle";
		
	},
	onTitleMouseout:function()
	{
		var element   = Yacon.getTR(event.srcElement);
		if(element.acton=="false" || element.acton==null){
			element.className = "leveltitle";
		}
	},
	//ÇåÀí±êÌâµÄÑ¡ÖÐ×´Ì¬
	clearActState:function(){
		var rootmenu = document.getElementById("mainmenu");
		var rootmenuRows = rootmenu.rows ;
		for(var i=0;i<rootmenuRows.length;i++){
			var titleRows = rootmenuRows[i].cells[0].children[0].rows ;
			var actRow = titleRows[0] ;
			actRow.className = "leveltitle";
			actRow.acton="false" ;
		}
	},
	onItemClick:function()
	{
		var element   = Yacon.getTR(event.srcElement);			
		var clickName = element.getAttribute("menuclick");		
		if (Yacon.isEmpty(clickName))
		{
			var chTable = Yacon.getTable(Yacon.getTable(element).parentNode);
			if (chTable.Control)
			{
				if(chTable.Control.activeItem!=element){
					if (chTable.Control.activeItem)
						chTable.Control.activeItem.className="";
				}
								
				chTable.Control.activeItem = element;
				chTable.Control.setMenuPage(element);
				
			}
		}else if (Yacon.getInt(clickName)<0)
		{
			Yacon.fireUserEvent(clickName+"_onclick");
		}
		this.clearActState() ;
	},
	onItemMouseover:function()
	{
		var element   = Yacon.getTR(event.srcElement);
		element.className = "aitem";
	},
	onItemMouseout:function()
	{
		var element   = Yacon.getTR(event.srcElement);
		var chTable = Yacon.getTable(Yacon.getTable(element).parentNode);
		if ( chTable.Control &&  chTable.Control.activeItem != element)
			element.className="";	
	}
}
function topmenu_item_mouseover(el)
{
	el.className="span_act";		
}
function topmenu_item_mouseout(el)
{
	if(el.actionon!="true"){
		el.className="";	
	}
}
function topmenu_item_click(el)
{
	var topmenu = document.getElementById("topmenu") ;
	var spanArr = topmenu.getElementsByTagName("span") ;
	for(var i=0;i<spanArr.length;i++){
		spanArr[i].className = "" ;
		spanArr[i].actionon = "false" ;
	}
	el.className="span_act";	
	el.actionon = "true" ;

	if(!Yacon.isEmpty(el.url)){
		parent.window.mainFrame.middleFrame.document.getElementById("frmTitle").style.display = "none"
		parent.window.mainFrame.middleFrame.workFrame.location.replace(contextPath + el.url);
	}else{
		parent.window.mainFrame.middleFrame.document.getElementById("frmTitle").style.display = ""
		parent.window.mainFrame.middleFrame.leftFrame.location.replace(contextPath + "/frames/general/left.jsp?id="+el.getAttribute("id"));
	}

	/*var clickName = el.getAttribute("menuclick");
	alert(el.getAttribute("id"));
	if (Yacon.isEmpty(clickName)||clickName.isEqual(""))
	{
		parent.window.mainFrame.middleFrame.leftFrame.location.replace(contextPath + "left.jsp?id="+el.getAttribute("id"));
	}else
	{
		Yacon.fireUserEvent(clickName+"_onclick");
	}*/
}
